use std::process::{exit, Command};
///对mount overlayfs的封装
pub fn container_overlayfs(image_dir:String,container_dir:String,work_dir:String,runtime_dir:String){
    modprobe();
    // mount -t overlay overlay -o lowerdir=./lower/,upperdir=./upper/,workdir=./tmp/ ./merge
    let mut mount_child = Command::new("mount")
        .arg("-t")
        .arg("overlay")
        .arg("overlay")
        .arg("-o")
        .arg(format!("lowerdir={},upperdir={},workdir={}", image_dir.clone(), container_dir.clone(), work_dir.clone()))
        .arg(runtime_dir.clone())
        .spawn()
        .expect("Mount command failed to start");
    let status = mount_child.wait().expect("Mount command failed wait");
    if !status.success(){
        exit(status.code().expect("Mount command failed with no exit code"));
    }


}
fn modprobe(){
    let mut child = Command::new("modprobe")
        .arg("overlay")
        .spawn()
        .expect("modprobe failed");
    let status = child.wait().expect("modprobe failed");
    let i = status.code().expect("modprobe terminated failed");
    if i!=0 {
        println!("modprobe terminated with exit code {}", i);
        exit(i);
    }
}